package com.company;

import com.company.command.*;

/**
 * 命令设计模式测试代码
 */
public class TestForCommand {

    public static void main(String[] args) {
        //接收者角色，遥控车
        RemoteControlCarReceiver receiver = new RemoteControlCarReceiver();

        //抽象命令和具体命令角色，开机、前、后、左、右、关机命令对象，设置命令对象的接受者
        Command onCommand = new OnCommand(receiver);
        Command forwardCommand = new ForwardCommand(receiver);
        Command backCommand = new BackCommand(receiver);
        Command leftCommand = new LeftCommand(receiver);
        Command rightCommand = new RightCommand(receiver);
        Command offCommand = new OffCommand(receiver);

        //请求者角色，遥控器，把命令对象设置进去
        RemoteControlInvoker remoteControl = new RemoteControlInvoker();
        remoteControl.setOnCommand(onCommand);
        remoteControl.setForwardCommand(forwardCommand);
        remoteControl.setBackCommand(backCommand);
        remoteControl.setLeftCommand(leftCommand);
        remoteControl.setRightCommand(rightCommand);
        remoteControl.setOffCommand(offCommand);

        //执行开机命令
        remoteControl.on();
        System.out.println();

        //执行前进命令
        remoteControl.forward();
        System.out.println();

        //执行左转命令
        remoteControl.left();
        System.out.println();

        //执行右转命令
        remoteControl.right();
        System.out.println();

        //执行后退命令
        remoteControl.back();
        System.out.println();

        //执行关机命令
        remoteControl.off();
        System.out.println();

    }
}
